﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace K9Nano.IM.Extensions
{
    public static class QueryableExtensions
    {
        public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
        {
            return condition ? query.Where(predicate) : query;
        }

        public static IQueryable<T> WhereIfNotEmpty<T>(this IQueryable<T> query, string text, Expression<Func<T, bool>> predicate)
        {
            return query.WhereIf(!string.IsNullOrEmpty(text), predicate);
        }
    }
}